//
//  threeTableViewCell.m
//  lmq
//
//  Created by 千翼网络科技 on 2017/4/12.
//  Copyright © 2017年 yuanxin. All rights reserved.
//

#import "threeTableViewCell.h"
#import "configddd.h"
#import <Masonry/Masonry.h>

@implementation threeTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:@"threeTableViewCell"]) {
        
        [self initView];
    }
    return self;
}

#pragma mark ---------------- init -----------------

- (void)initView{
    
    self.backgroundColor = getColor(@"ffffff");
    
    _threadView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, scrWidth(), screenScale(8))];
    _threadView.backgroundColor = getColor(@"f4f4f4");
    [self addSubview:_threadView];
    
    _stateLable = [[UILabel alloc]init];
    _stateLable.text = @"交易状态";
    _stateLable.textColor = [UIColor redColor];
    _stateLable.textAlignment = NSTextAlignmentCenter;
    _stateLable.font = get4sFont(13);
    [self addSubview:_stateLable];
    [_stateLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_threadView.mas_bottom).with.offset(0);
        make.left.mas_equalTo(self).with.offset(0);
        make.width.mas_equalTo(screenScale(120));
        make.height.mas_equalTo(screenScale(60));
    }];
    
    _threadView1 = [[UIView alloc]initWithFrame:CGRectMake(0, screenScale(70), scrWidth(), screenScale(1))];
    _threadView1.backgroundColor = getColor(@"c1c1c1");
    [self addSubview:_threadView1];
    
    _threadView2 = [[UIView alloc]initWithFrame:CGRectMake(screenScale(120), screenScale(10), screenScale(1), screenScale(60))];
    _threadView2.backgroundColor = getColor(@"c1c1c1");
    [self addSubview:_threadView2];
    
    _dateLable = [[UILabel alloc]init];
    _dateLable.text = @"2017-04-05 11:23:12";
    _dateLable.textColor = getColor(@"6f6f6f");
    _dateLable.textAlignment = NSTextAlignmentRight;
    _dateLable.font = get4sFont(12);
    [self addSubview:_dateLable];
    [_dateLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_threadView.mas_bottom).with.offset(0);
        make.right.mas_equalTo(self).with.offset(screenScale(-20));
        
        make.height.mas_equalTo(screenScale(60));
    }];
    
    _logoImg = [[UIImageView alloc]init];
    [self addSubview:_logoImg];
    [_logoImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_threadView1.mas_bottom).with.offset(screenScale(20));
        make.left.mas_equalTo(self).with.offset(screenScale(20));
        make.width.mas_equalTo(screenScale(130));
        make.height.mas_equalTo(screenScale(130));
    }];
    
    _nameTextView = [[UITextView alloc]init];
    _nameTextView.text = @"大米饭大米饭大米饭";
    _nameTextView.font = get4sFont(12);
    _nameTextView.textColor = getColor(@"242424");
    _nameTextView.editable = NO;
    [self addSubview:_nameTextView];
    [_nameTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_threadView1.mas_bottom).with.offset(screenScale(10));
        make.left.mas_equalTo(_logoImg.mas_right).with.offset(screenScale(20));
        make.width.mas_equalTo(screenScale(350));
        make.height.mas_equalTo(screenScale(125));
    }];
    
    _priceLable = [[UILabel alloc]init];
    _priceLable.text = @"0.01";
    _priceLable.textColor = getColor(@"6f6f6f");
    _priceLable.textAlignment = NSTextAlignmentRight;
    _priceLable.font = get4sFont(12);
    [self addSubview:_priceLable];
    [_priceLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_threadView1.mas_bottom).with.offset(screenScale(20));
        make.right.mas_equalTo(self).with.offset(screenScale(-20));
        
        make.height.mas_equalTo(screenScale(26));
    }];
    
    _numLable = [[UILabel alloc]init];
    _numLable.text = @"2";
    _numLable.textColor = getColor(@"6f6f6f");
    _numLable.textAlignment = NSTextAlignmentRight;
    _numLable.font = get4sFont(12);
    [self addSubview:_numLable];
    [_numLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_threadView1.mas_bottom).with.offset(screenScale(66));
        make.right.mas_equalTo(self).with.offset(screenScale(-20));
        
        make.height.mas_equalTo(screenScale(26));
    }];
    
    _threadView3 = [[UIView alloc]init];
    _threadView3.backgroundColor = getColor(@"c1c1c1");
    [self addSubview:_threadView3];
    [_threadView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_threadView1.mas_bottom).with.offset(screenScale(170));
        make.left.mas_equalTo(self).with.offset(0);
        make.width.mas_equalTo(scrWidth());
        make.height.mas_equalTo(screenScale(1));
    }];
    
    _codeLable = [[UILabel alloc]init];
    _codeLable.text = @"识别码：";
    _codeLable.textColor = getColor(@"242424");
    _codeLable.textAlignment = NSTextAlignmentRight;
    _codeLable.font = get4sFont(14);
    [self addSubview:_codeLable];
    [_codeLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_threadView3.mas_bottom).with.offset(0);
        make.left.mas_equalTo(self).with.offset(screenScale(20));
        
        make.height.mas_equalTo(screenScale(75));
    }];
    
    _moneyLable = [[UILabel alloc]init];
    _moneyLable.text = @"总价";
    _moneyLable.textColor = getColor(@"242424");
    _moneyLable.textAlignment = NSTextAlignmentRight;
    _moneyLable.font = get4sFont(14);
    [self addSubview:_moneyLable];
    [_moneyLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_threadView3.mas_bottom).with.offset(0);
        make.right.mas_equalTo(self).with.offset(screenScale(-20));
        
        make.height.mas_equalTo(screenScale(75));
    }];
    
    _threadView4 = [[UIView alloc]init];
    _threadView4.backgroundColor = getColor(@"c1c1c1");
    [self addSubview:_threadView4];
    [_threadView4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_threadView3.mas_bottom).with.offset(screenScale(75));
        make.left.mas_equalTo(self).with.offset(0);
        make.width.mas_equalTo(scrWidth());
        make.height.mas_equalTo(screenScale(1));
    }];
    
    _payBtn = [[UIButton alloc]init];
    _payBtn.backgroundColor = getColor(@"242424");
    _payBtn.titleLabel.font = get4sFont(13);
    [_payBtn setTitle:@"退款" forState:UIControlStateNormal];
    [_payBtn setTitleColor:getColor(@"ffffff") forState:UIControlStateNormal];
    [_payBtn addTarget:self action:@selector(refundBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_payBtn];
    [_payBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_threadView4.mas_bottom).with.offset(screenScale(20));
        make.right.mas_equalTo(self).with.offset(screenScale(screenScale(-20)));
        make.width.mas_equalTo(screenScale(120));
        make.height.mas_equalTo(screenScale(50));
    }];
}

#pragma mark ------------ click ------------

- (void)refundBtnClick{
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[[UIApplication sharedApplication]keyWindow] animated:YES];
    hud.tag = 500;
    //提示文本
    hud.labelText = @"正在加载...";
    //是否有遮罩
    hud.dimBackground = NO;
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    [productParams setValue: [PublicFunction getConfigWithKey:@"token"] forKey:@"token"];
    [productParams setValue: _orderId forKey:@"id"];
    
    [[MNetworkHandler sharedInstance]conURL:Refund_Order
                                networkType:NetWorkPOST
                                     params:productParams
                                   delegate:nil
                                    showHUD:NO
                               successBlock:^(id returnData) {
                                   if ([[returnData objectForKey:@"code"]intValue]==1) {
                                       
                                       NSDictionary *dict =[[NSDictionary alloc]initWithObjectsAndKeys:@"yes",@"selected", nil];
                                       NSNotification *notification =[NSNotification notificationWithName:@"refund" object:nil userInfo:dict];
                                       [[NSNotificationCenter defaultCenter] postNotification:notification];
                                       [hud removeFromSuperview];
                                       
                                       [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
                                       
                                   }
                                   else{
                                       
                                       [hud removeFromSuperview];
                                       [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
                                       
                                   }
                               } failureBlock:^(NSError *error) {
                                   
                                   [hud removeFromSuperview];
                                   NSLog(@"%@",error);
                                   [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
                               }];
}

@end
